// pages/home/home.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
       imageSrc : ["/static/source/房6.png","/static/source/房2.png","/static/source/房3.png","/static/source/房4.png"],
      // houseTitleList : ["房产资源1","房产资源2","房产资源3","房产资源4"],
      // houseAddList : ["格园1斋357室","格园1斋257室","齐园1斋357室","诚园1斋357室"],
      // houseTypeList : ["一室一厅","一室一厅","一室一厅","一室一厅"],
      // houseAreaList : ["20㎡","20㎡","20㎡","20㎡"],

      search_str:"",
      datas:[{ 
      id:0,
      username:"",
      title:"房产资源1",
      kind:"出租",
      phone:"",
      lease:"",
      isjoint:"",
      requirement:"",
      funiture:"",
     
     

      rights:"",
      type:"一室一厅",
      orentation:"",
      floor:"",
      decoration:"",
      elevator:"",
      date:"",
      area:20,
      price:0,
      location:"格园1斋357室",
      date:"",
      picture:"/static/source/房1.png",
      other:""
     },{ 
      id:14,
      username:"",
      title:"房产资源1",
      kind:"",
      phone:"",
      lease:"",
      isjoint:"",
      requirement:"",
      funiture:"",
     
     

      rights:"",
      type:"一室一厅",
      orentation:"",
      floor:"",
      decoration:"",
      elevator:"",
      date:"",
      area:20,
      price:0,
      location:"格园1斋357室",
      date:"",
      picture:"/static/source/房1.png",
      other:""
     }
  ],
       
      token:"",
      message:"",
      username:""
      
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      var that = this
      try {
        var value = wx.getStorageSync('token')
        var value2 = wx.getStorageSync('username')
        if (value) {
          that.setData({token:value,username:value2})
        }
      } catch (e) {
        // Do something when catch error
        console.log("异常：获取用户token异常")
      }
      
      wx.request({
        url: 'http://172.23.144.125:8081/house/v1/otherinfo/'+that.data.username+'/'+that.data.token,
        //data:{token:this.data.token},

        method:"GET",
        success:function(res){

          if(res.data.code==200){
            console.log("code:"+res.data.code)
            console.log("messagef:"+res.data.message)
            console.log("datas:"+res.data.datas[0].id)
            console.log(res.data.datas[0].price)
            that.setData({
              datas:res.data.datas
              
            })
          }
          else{
            console.log(res.data.message)
            console.log("code:"+res.data.code)
            console.log("datas:"+res.data.datas[0])
          }
        },
        fail:function(res){
          console.log("异常：获取房屋信息失败")
        }
      })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
      wx.startPullDownRefresh()

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    /*
    * 点击操作函数
    */
   clickMe:function(e){
        console.log(e)
        var nid = e.currentTarget.dataset.nid;
        wx.navigateTo({//该函数只能跳转到非tabBar的页面
          url: '/pages/redirect/redirect?id='+nid,
        })
   },
   report_mes:function(e){
    console.log(e)
    wx.navigateTo({
      url: '/pages/home/report/report?id='+e.currentTarget.dataset.id,
    })
   },
  searchInput:function(e)
  {
      this.setData(this.data.search_str=e.detail.value)
      console.log(this.data.search_str)
  },
  searchClick:function(e)
  {
    wx.setStorageSync('search_str', this.data.search_str)
    if(this.data.search_str != ""){
      wx.navigateTo({
        url: '/pages/home/searchpage/searchpage',
      })
    }
    
  }
})